package client.vue;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JPanel;
import javax.swing.JTextField;

import serveur.controller.Serveur;
import client.controller.JeuxController; 

public class ImageVue extends JPanel{

	private Image image;
	File file;
	int width=240;
	int height=240;
	public ImageVue(){
		this.setPreferredSize(new Dimension(width,height));
		this.file = new File("src/client/image/default.jpeg");
		loadImage();
	}
	
	public void setImage(String value){
		this.file = new File("src/client/image/"+value+".jpeg");
		loadImage();
	}
	String test=null;
	public String setImageById(String id){
		
		File repertoire = new File("src/client/image/");
		String[] listeImage = repertoire.list();
		for(int i=0;i<listeImage.length;i++){
			if(listeImage[i].split("-")[0].equals(id)){	
				 this.test = listeImage[i].split("-")[1];
				this.file =  new File("src/client/image/"+listeImage[i].substring(0,listeImage[i].length()));
				loadImage();
			}
		}
		return null;
	}
	
	public String getTest(){
		if(test==null){
			return "pb";
		}
		return test;
		
	}
	
	private void loadImage() {
		try {
			image=(ImageIO.read(file));
		} catch (IOException e) {
			System.out.println("pb image");
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		image = image.getScaledInstance(width, height, Image.SCALE_FAST);
		repaint();
	}
	public void paintComponent(Graphics g){
		super.paintComponent(g);
		g.drawImage(image,0,0,null);
	}
}
